package com.df.actions;



import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.df.managers.UserManager;
import com.df.user.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype") 
public class UserAction extends ActionSupport {
	@Resource
	private UserManager userManager;
	private String page = "index";
	private User user;
	private int id;
	public String execute(){
	   ActionContext.getContext().put("pm", userManager.list());
		return SUCCESS;
	}
	public String addInput() throws Exception {
		page = "add";
		return SUCCESS;
	}
	
	public String add(){
		userManager.add(user);
		return "pub_add";
	}
	
	public String updateInput(){
		user = userManager.getById(id);
		page = "update";
		return SUCCESS;
	}
	
	public String update(){
		userManager.update(user);
		return "pub_update";
	}
	public String del(){
		userManager.del(id);
		return "pub_del";
	}
	public String login(){
		user = (User) userManager.getUser(user.getUname(),user.getPwd());
		if(user!=null){
			 ActionContext.getContext().getSession().put("user", user);
			 return LOGIN;
		}else{
			 return INPUT;
		}
	}
	public UserManager getUserManager() {
		return userManager;
	}
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	
}
